package yc.gg.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import yc.gg.Interceptor.LoginInterceptor;
import yc.gg.properties.SecurityProperties;


@Configuration
@Slf4j
public class MvcConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Autowired
    private SecurityProperties securityProperties;

    public MvcConfig() {
        log.info("MvcConfig 已初始化");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        String[] excludes = securityProperties.getExcludes();
//        log.info("拦截器排除路径: {}", Arrays.toString(excludes));
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(excludes);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**")
                .addResourceLocations("classpath:/static/");
    }
}